package com.leo.basic.chapter01;

/**
 * 递归复习第一遍
 * @author xuexiaolei
 * @version 2017年12月07日
 */
public class P01Recursion01 {
    public static int fab(int i){
        if (i < 2) return i;
        return fab(i-1)+fab(i-2);
    }

    /**
     * 不够简练！！！！！！！！
     * @param i
     */
    public static void p(int i){
//        if (i < 10){
//            System.out.print(i);
//        }else {
//            System.out.print(i%10);
//            p(i/10);
//        }

        ///修正
        System.out.println(i%10);
        if (i>10){  //注意i>10  和 i>=10的区别!!!!!
            p(i/10);
        }
    }

    public static void hanio(int n, char from, char to, char tmp){
        if (n>0){
            hanio(n-1, from, tmp, to);
            System.out.println("move " + n + " from " + from +" to " + to );
            hanio(n-1, tmp, to, from);
        }
    }

    public static void pai(int[] l, int k){
        if (k == l.length-1){
            for (int i = 0; i < l.length; i++) {
                System.out.print(l[i]+" ");
            }
            System.out.println();
        }else {
            for (int i = k; i < l.length; i++) {
                int tmp = l[k]; l[k]=l[i]; l[i]=tmp;
                pai(l, k+1);
                tmp = l[k]; l[k]=l[i]; l[i]=tmp;
            }
        }
    }

    public static void zu(int[] l, boolean[] b, int k){
        if (k == l.length-1){
            for (int i = 0; i < l.length; i++) {
                if (b[i]) System.out.print(l[i] + " ");
            }
            System.out.println();
        }else {
            b[k] = true;
            zu(l, b, k+1);
            b[k] = false;
            zu(l, b, k+1);
        }
    }

    /**
     * 重写
     * @param i
     */
    public static void daoP(int i){
        System.out.print(i%10);
        if (i>10) daoP(1/10);
    }
}
